home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11390 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  49 lines

  1. Newsgroups: comp.lang.c++
  2. Path: netcom.com!mikenann
  3. From: Michael Glassman and Ann Ross <mikenann@netcom.com>
  4. Subject: Re: C++ keyword
  5. Content-Type: text/plain; charset=us-ascii
  6. Message-ID: <3147CBC6.7CA1@netcom.com>
  7. Sender: mikenann@netcom21.netcom.com
  8. Content-Transfer-Encoding: 7bit
  9. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  10. References: <mwoods-1403961501550001@ou048057.otago.ac.nz>
  11. Mime-Version: 1.0
  12. Date: Thu, 14 Mar 1996 07:33:26 GMT
  13. X-Mailer: Mozilla 2.0 (Win16; I)
  14.  
  15. Matt B. Woods wrote:
  16. > I am fairly new to C++ and I have just come across the keyword 'throw'.
  17. > As I cannot find a reference to this keyword I assume I must be reading
  18. > the wrong books.  Can anyone tell me what 'throw' means?  Even better
  19. > could someone recommend a good complete reference to the C++ language?
  20.  
  21. Very briefly:
  22. Throw is the C++ keyword to raise exceptions. Throw with an argument raises the 
  23. exception designated by the argument; throw without an argument raises the 
  24. currently caught exception. Throw without an argument can only be used within a 
  25. catch block.
  26.  
  27. Simple example:
  28.  
  29. try
  30. {
  31.     // do some stuff
  32.     throw anException;
  33. }
  34. catch( ExceptionType& caughtException )
  35. {
  36.     // handle exceptions of type ExceptionType
  37. }
  38. catch(...)
  39. {
  40.     // handle all other exceptions
  41. }
  42.  
  43. My favorite 'complete reference to the C++ language' is The Annotated C++ 
  44. Reference Manual by Ellis and Stroustrup. It is usually refered to as the ARM.
  45.  
  46. Michael Glassman
  47.